package com.jason.game.online.utils

import com.cby.library.common.util.ScreenUtils.sp2px
import com.cby.library.widget.TintButton
import com.jason.game.online.utils.ChangeButtonStyleUtils
import com.jason.game.online.R
import android.widget.TextView
import com.cby.library.common.ext.setFontColor

/**
 * @author 3050
 * @create 2020/11/28
 * 更改Button的背景和字体样式
 */
object ChangeButtonStyleUtils {
    /**
     * 0 非测试模式
     * 1 正在测试
     * 2 结束测试 （也就是敬请期待）
     */
    const val API_UN_TEST_MODEL = "0"
    const val API_TEST_MODEL_START = "1"
    const val API_TEST_MODEL_END = "2"

    /**
     * 列表item开始玩小按钮
     */
    @JvmStatic
    fun changeButtonStyle(button: TintButton, testState: String?) {
        button.isClickable = false
        if (testState != null && testState == API_TEST_MODEL_END) {
            button.paint.textSize =
                sp2px(button.context, 12f).toFloat()
            button.setText(R.string.game_list_item_state_text)
            button.setFontColor(R.color.game_list_test_time_end_color)
            button.setBackgroundResource(R.drawable.bg_game_list_item_button_unselected)
        } else {
            button.isClickable = true
            button.textSize = 13f
            button.setText(R.string.game_start)
            button.setFontColor(R.color.colorAccent)
            button.setBackgroundResource(R.drawable.bg_game_list_item_button_selected)
        }
    }

    fun changeTextViewButtonStyle(button: TextView, testState: String?) {
        if (testState != null && testState == API_TEST_MODEL_END) {
            button.isClickable = false
            button.setText(R.string.game_list_item_state_text)
            button.setFontColor(R.color.game_list_test_time_end_color)
            button.setBackgroundResource(R.drawable.bg_game_list_item_button_unselected)
        } else {
            button.isClickable = true
            button.setText(R.string.game_start)
            button.setFontColor(R.color.colorAccent)
            button.setBackgroundResource(R.drawable.bg_game_list_item_button_selected)
        }
    }

    /**
     * 游戏详情开始游戏大按钮
     */
    fun changeButtonStyleLarge(button: TintButton, testState: String?) {
        if (testState != null && testState == API_TEST_MODEL_END) {
            button.isClickable = false
            button.setText(R.string.game_list_item_state_text)
            button.setFontColor(R.color.white)
            button.setBackgroundResource(R.drawable.bg_game_detail_play_button_large_unselected)
        } else {
            button.isClickable = true
        }
    }
}